#ifndef NEUTRON_DETECTOR_HPP
#define NEUTRON_DETECTOR_HPP

#include "detector_base.hpp"
#include <geometry_msgs/msg/point_stamped.hpp>
#include <vector>
#include <opencv2/opencv.hpp>

namespace center_detection {

    struct NeutronDetectionParams
    {
        //高度切片参数
        float search_start_z = 0.35f;
        float search_end_z = 0.05f;
        float search_step = 0.01f;
        float height_range = 0.15;
        int min_points_in_slice = 50;
        float neutron_height = 0.3f;
        //矩形拟合参数:最大最小面积
        float rect_min_area = 0.01f;
        float rect_max_area = 0.1f;

    };

    class NeutronDetector : public DetectorBase {

    public:

        NeutronDetector() = default;
        ~NeutronDetector() = default;

        bool detectCenter(PointCloud cloud, 
                        geometry_msgs::msg::PointStamped& center_point) override;

        void setParameters(rclcpp::Node* node) override;

    private:

        NeutronDetectionParams params_;

        //检测顶部区域
        PointCloud detectTopRegion(const PointCloud& cloud, float& detected_z);

        //投影到XY平面
        std::vector<cv::Point2f> projectTo2D(const PointCloud& cloud);

        //拟合矩形
        bool fitRectangleAndGetCenter(const std::vector<cv::Point2f>& points,
                        cv::Point2f& center);

    };
    
}

#endif